package ONLINE_EXAM;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class hw_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while ((str = br.readLine())!= null){
            str = str.substring(2);
            int res=0;
            for (int i =0;i<str.length();i++){
                int num;
                if (str.charAt(i) <58){
                    num = str.charAt(i)-48;
                }else {
                    num = str.charAt(i) - 55;
                }
                res += num * Math.pow(16,str.length()-i-1);

            }

            System.out.println(res);

        }
    }
}
